<template>
  <div>
    <div style="margin-top:100px;width: 100%;height: 400px;" id="statistic_id"></div>
  </div>
</template>

<script>

import * as echarts from 'echarts';
import orderService from '@/global/service/orderService';

export default {
  name: 'statistic',
  data() {
    return {
      myChart: null,
      dates: [],
      quantites: [],
    }
  },
  mounted() {
    this.getOrderStatisticData()
  },
  methods: {
    draw() {
// 基于准备好的dom，初始化echarts实例
      this.myChart = echarts.init(document.getElementById('statistic_id'));
// 绘制图表
      this.myChart.setOption({
        title: {
          text: '每日订单',
          textAlign: 'right',
          x: 'center',
          y: 'top',
        },
        xAxis: {
          type: 'category',
          name: '日期',
          data: this.dates,
        },
        yAxis: {
          type: 'value',
          name: '订单数量',
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {type: 'cross'},
        },
        series: [
          {
            type: 'line',
            smooth: true,
            data: this.quantites,
          },
        ],
      });
    },
    getOrderStatisticData() {
      orderService.statistic().then((res) => {
        this.dates = res.dates;
        this.quantites = res.quantities;
        this.draw();
      })
    },
  },
}
</script>

<style scoped>

</style>
